<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

/**
 * App\User
 *
 * @property int $id
 * @property string|null $name
 * @property string|null $email
 * @property string|null $password
 * @property string|null $remember_token
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @property string|null $mobile
 * @property string|null $true_name 真实姓名
 * @property int|null $team_level_id 会员等级id 0 普通会员
 * @property int|null $distribution_money 分销金额 按分计算
 * @property int|null $distribution_used_money 分销已提现的金额
 * @property int|null $money 总金额
 * @property int|null $team_money 用户团队奖励金额
 * @property int|null $team_used_money 团队已提现金额
 * @property string|null $openid openid
 * @property string|null $team_path 团队树节点 用,分割
 * @property int|null $team_leader 上级领导
 * @property string|null $headimgurl 微信头像
 * @property int|null $sex
 * @property string|null $city
 * @property string|null $province
 * @property string|null $country
 * @property int|null $promotion_number 推广人数 判断团队升级等级
 * @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCity($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCountry($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereDistributionMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereDistributionUsedMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereHeadimgurl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereMobile($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereOpenid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePromotionNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereProvince($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRememberToken($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereSex($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTeamLeader($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTeamLevelId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTeamMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTeamPath($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTeamUsedMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTrueName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property int|null $is_recharge 是否是复购 0 否 1 是
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereIsRecharge($value)
 * @property-read \App\UserTeam|null $team
 * @property-read \App\User $leader
 * @property float|null $consume 消费额
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereConsume($value)
 * @property float|null $distribution_total_sale 推广订单销售量
 * @property float|null $team_total_sale 团队订单销售量
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereDistributionTotalSale($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereTeamTotalSale($value)
 * @property int|null $is_regrade 0可以降级 1 不可以降级
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereIsRegrade($value)
 * @property int|null $subscribe 是否关注 0 未关注 1关注
 * @property string|null $subscribe_time
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereSubscribe($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\User whereSubscribeTime($value)
 */
class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',  'password','openid',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
    public function getTeamPathAttribute($key)
    {
        if($key){
            return explode(',',$key);
        }else{
            return [];
        }


    }
    public function team(){
        return $this->belongsTo('App\UserTeam','team_level_id','level');
    }
    public function leader(){
        return $this->belongsTo('App\User','leader_id');
    }

}
